#!/bin/sh

export MY_WORKDIR=$PWD

echo "workdir: $MY_WORKDIR"

echo "restoring my $HOME variable"
export HOME=~/
if [ -f $HOME/.bashrc ]; then
    source $HOME/.bashrc
fi
echo "home: $HOME"

export ATLAS_LOCAL_AREA=/opt/atlas/local
export VO_ATLAS_DEFAULT_SE=srm.grid.sara.nl
export VO_ATLAS_SW_DIR=/cvmfs/atlas.cern.ch/repo/sw

export X509_USER_PROXY=$MY_WORKDIR/$GANGA_PROXY_NAME

source /opt/cvmfs/cvmfs_setup.sh
setupATLAS
localSetupGLite

## check proxy validity
#voms-proxy-info -exists -valid 24:00:00

#if [ $? != 0 ]; then
#    voms-proxy-init -voms atlas -valid 96:00:00
#fi

export RUCIO_ACCOUNT=pilot

## switch dCache to client active (server-passive) mode
export DCACHE_CLIENT_ACTIVE=1

chmod +x $MY_WORKDIR/runpilot3-wrapper.sh

$MY_WORKDIR/runpilot3-wrapper.sh -s ANALY_SARA_hpc_cloud -h ANALY_SARA_hpc_cloud -p 25443 -w 'https://pandaserver.cern.ch' -j false -k 0 -C 86400 -u user 

## remove un-necessary files for output transfer
rm -rf $MY_WORKDIR/$GANGA_PROXY_NAME
rm -rf $MY_WORKDIR/runpilot3-wrapper.sh
